package com.xisoft.devise.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xisoft.devise.entity.TableColEntity;
import com.xisoft.devise.entity.TableEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * *
 * Created with Description:
 *
 * @version 1.0 <br>
 * @packagename: com.xisoft.generator.mapper<br>
 * @author: LiBencheng <br>
 * @computer: licheng <br>
 * @date: Created on 2022/8/5 10:36 <br>
 */
@Mapper
public interface IGeneratorMapper extends BaseMapper
{

    @Select ("SELECT\n" +
            "  dt.table_name    AS \"code\",\n" +
            "  replace(initcap(lower(substr(dt.table_name, instr(dt.table_name, '_')))), '_', '') AS \"classname\"," +
            "  dt.table_name    AS \"tablename\",\n" +
            "  dtc.comments     AS \"tablecomments\",\n" +
            "  uo.last_ddl_time AS \"createtime\",\n" +
            "  uo.object_type   AS \"tabletype\",\n" +
            "  ROWNUM AS rn\n" +
            "FROM\n" +
            "  user_tables         dt\n" +
            "  LEFT JOIN user_tab_comments   dtc ON dtc.table_name = dt.table_name\n" +
            "  LEFT JOIN user_objects        uo ON uo.object_name = dt.table_name\n" +
            "WHERE  (lower(dt.table_name)=#{table} OR upper(dt.table_name)=#{table})")
    TableEntity getTableInfo(@Param ("table") String table);

    @Select ("${sqlStr}")
    IPage< TableEntity > selectPage(@Param ("sqlStr") String dynamicSql, Page page, @Param ("ew") Wrapper queryWrapper);

    @Select ("${sqlStr}")
    List< TableColEntity > getFieldList(@Param ("sqlStr") String dynamicSql);

    @Select ("SELECT referinfo FROM sys_dic_table_field WHERE upper(sdt_table_en_name)=#{table} "
            + "and upper(sdf_field_en_name)=#{field}")
    Map< String,Object > getRefer(@Param ("table") String table, @Param ("field") String field);


}
